package com.example.take_out_dish.controller;

import com.example.take_out_dish.common.PageResult;
import com.example.take_out_dish.common.Result;
import com.example.take_out_dish.common.lang.dto.SetmealDTO;
import com.example.take_out_dish.common.lang.dto.SetmealPageQueryDTO;
import com.example.take_out_dish.common.lang.vo.SetmealVO;
import com.example.take_out_dish.service.SetmealService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 套餐 前端控制器
 * </p>
 */
@Slf4j
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Resource
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param source
     * @return
     */
    @PostMapping
    public Result save(@RequestBody SetmealDTO source){
        setmealService.saveWithDish(source);
        return Result.success();
    }

    /**
     * 套餐分页查询
     * @param source
     * @return
     */
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody SetmealPageQueryDTO source){
        log.info("/setmeal/page source:{}", source.toString());
        return Result.success(setmealService.page(source));
    }

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestBody List<String> ids){
        setmealService.delete(ids);
        return Result.success();
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable("id") String id){
        return Result.success(setmealService.getById(id));
    }

    /**
     * 修改套餐
     * @param source
     * @return
     */
    @PutMapping
    public Result update(@RequestBody SetmealDTO source){
        setmealService.update(source);
        return Result.success();
    }

    /**
     * 套餐起售停售
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}/{id}")
    public Result startOrStop(@PathVariable("status") Integer status,
                              @PathVariable("id") String id){
        setmealService.startOrStop(status,id);
        return Result.success();
    }
}
